package com.stox.ui.javafx.core.widget;

import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.core.util.MessageSource;
import com.stox.ui.javafx.core.widget.wrapper.ImageView;
import com.stox.ui.javafx.core.widget.wrapper.MenuBar;
import com.stox.ui.javafx.core.widget.wrapper.ToolBar;

@Component
public class StoxStage extends Stage implements InitializingBean{
	
	@Autowired
	private MenuBar menuBar;

	@Autowired
	private MessagePane messagePane;
	
	@Autowired
	private ToolBar toolBar;
	
	private static Pane root = new BorderPane();
	
	private static Pane contentPane = new StackPane();
	
	public static Pane getRoot() {
		return root;
	}
	
	public static Pane getContentPane() {
		return contentPane;
	}
	
	public StoxStage() {
		super();
		setTitle(MessageSource.getMessage("application.name"));
		setMaximized(true);
		getIcons().add(new ImageView("icon-title.png").getImage());
		
		Scene scene  = new Scene(root, getWidth(),getHeight(), Color.BLACK);
		setScene(scene);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Platform.runLater(new Runnable() {
			@Override
			public void run() {
				BorderPane borderPane = (BorderPane)getScene().getRoot();
				VBox vBox = new VBox();
				vBox.getChildren().addAll(menuBar, toolBar);
				borderPane.setTop(vBox);
				borderPane.setCenter(contentPane);
				borderPane.setBottom(messagePane);
			}
		});
	}
	
}
